<?php
 	if ($mod=="load"){
		if ($act == "step1") {
			if ($type == "ms-xls"){
				require_once $setupdata['core_dir']."/modules/import/excel/reader.php";
				$data = new Spreadsheet_Excel_Reader();
				$data->setOutputEncoding('UTF-8');
				$error = $data->read($_FILES['import_file']['tmp_name']);
				if ($error != 0){
					$err->AddError($error);
				} else {
					$mysqlclass->mysql_my_query("DELETE FROM `".$setupdata['table_prefix']."import_temp` WHERE `session_id`='".session_id()."'", __LINE__, __FILE__);
					if (count($data->sheets) > 0){
						foreach($data->sheets as $key=>$sheet){
							if (isset($sheet['cells']) && (count($sheet['cells']) > 0)){
								foreach($sheet['cells'] as $row=>$cells){
									if (count($cells) > 0){
										foreach($cells as $col=>$value){
											$value = trim($value);
											$value = addslashes($value);
											$mysqlclass->mysql_my_query("INSERT INTO `".$setupdata['table_prefix']."import_temp` (`id`,`source`,`row`,`col`,`value`, `session_id`) VALUES	('', '".$key."', ".$row.", ".$col.", '".$value."', '".session_id()."')", __LINE__, __FILE__);
										}
									}
								}
							}
						}
					}
				}
			} else {
				
			}
			unset($data);
		} elseif ($act == "step2") {
			if (!isset($_GET['to'])) $to_module=NULL; else $to_module=$_GET['to'];
			if ($to_module==NULL) if (!isset($_POST['to'])) $to_module=NULL; else $to_module=$_POST['to'];
			if ($to_module == "shop"){
				if (!isset($_GET['product_name'])) $array['main']['name']=NULL; else $array['main']['name']=$_GET['product_name'];
				if ($array['main']['name']==NULL) if (!isset($_POST['product_name'])) $array['main']['name']=NULL; else $array['main']['name']=$_POST['product_name'];
				if (!isset($_GET['source'])) $array['main']['source']=NULL; else $array['main']['source']=$_GET['source'];
				if ($array['main']['source']==NULL) if (!isset($_POST['source'])) $array['main']['source']=NULL; else $array['main']['source']=$_POST['source'];
				if (!isset($_GET['group_id'])) $array['main']['group']=NULL; else $array['main']['group']=$_GET['group_id'];
				if ($array['main']['group']==NULL) if (!isset($_POST['group_id'])) $array['main']['group']=NULL; else $array['main']['group']=$_POST['group_id'];
				if (($array['main']['name'] != NULL) && ($array['main']['source'] != NULL) && ($array['main']['group'] != NULL)){


					foreach($_POST as $langs=>$arrays){
						if (in_array($langs, $lang_array2)) {
							foreach($arrays as $cell=>$param){
								if ((isset($param['col'])) && ($param['col'] != "-111")) $array['cols'][$langs][$param['col']] = $cell;
								if ((isset($param['rewrite'])) && ($param['rewrite']=='rewrite')){
									$array['rewrite'][$langs][$param['col']]['name'] = $cell;
									$array['rewrite'][$langs][$param['col']]['type'] = 'group';
								}
								if ((isset($param['rewrite'])) && ($param['rewrite']=='rewrite_global')){
									$array['rewrite'][$langs][$param['col']]['name'] = $cell;
									$array['rewrite'][$langs][$param['col']]['type'] = 'global';
								}
							}
						}
					}
		
					$array['main']['dublicate']=NULL;
					if (!isset($_GET['dublicate_action'])) $array['main']['dublicate']=NULL; else $array['main']['dublicate']=$_GET['dublicate_action'];
					if ($array['main']['dublicate']==NULL) if (!isset($_POST['dublicate_action'])) $array['main']['dublicate']=NULL; else $array['main']['dublicate']=$_POST['dublicate_action'];
					if ($array['main']['dublicate']==NULL) $array['main']['dublicate'] = 'skip';
										
					$importclass->import_products_to_shop($parent, $array);
				}
			}
		}
	} elseif ($mod=="reset"){
		$importclass->reset();
	}
?>